import util from '@/network/common/util_hq.js';
import $ from 'jquery'

let postCfg = {
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    transformRequest: function (data) {
        return $.param(data)
    }
}

let api = {
    'sendVCode'          : '/account/v1/sendVCode',//发送验证码
    'vertifyVCode'       : '/account/v1/vertifyVCode', // 验证验证码
};

let res = {};
function sendVCode (params) {
    let p = new Promise(function (resolve, reject) {
        util.ajax.post(api.sendVCode, {
            phone: params.phone,
            type: params.type,
        }, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}
function vertifyVCode (params) {
    let p = new Promise(function (resolve, reject) {
        util.ajax.post(api.vertifyVCode, {
            phone: params.phone,
            type: params.type,
            vcode: params.vcode
        }, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}

export default {
    sendVCode,
    vertifyVCode,
}